package jeconbond.economic.market.agent;

import jeconbond.economic.agent.IEconomicAgent;
import jeconbond.economic.resources.IResourceType;
import jeconbond.economic.resources.ResourceBasket;
import jeconbond.economic.resources.ResourceStorrage;
import jeconbond.economic.systems.market.IMarketResourceRedestributionSystem;
import jeconbond.economic.systems.market.IMoneyAccount;
import jeconbond.economic.systems.market.ISellProposition;
import jeconbond.economic.systems.market.MoneyAccount;
import jeconbond.economic.systems.market.SellProposition;

public class SellInitialResourcesAgent implements IEconomicAgent {
	private ResourceStorrage initialStorrage = new ResourceStorrage();
	private IMoneyAccount money = new MoneyAccount();
	private IMarketResourceRedestributionSystem mrrs;
	private double initialPrice = 1.0;

	public SellInitialResourcesAgent(
			IMarketResourceRedestributionSystem mrrs, 
			IResourceType[] resources, 
			int agentsCount, 
			int chainLength, 
			double exceedPercent
	) {
		this.mrrs = mrrs;
		double value = agentsCount * chainLength / resources.length;
		value *= exceedPercent;
		for (IResourceType type : resources) {
			initialStorrage.storeResource(type, value);
		}
	}

	@Override
	public void processPostProduceStage() {
		for (ResourceBasket rb : initialStorrage.listBaskets()) {
			ISellProposition sp = new SellProposition(
					rb.type,
					initialPrice,
					initialStorrage,
					money
			);
			mrrs.registerProposition(sp);
		}
	}

	@Override
	public void processPreProduceStage() {
	}

	@Override
	public void processProduceStage() {}

	public ResourceStorrage getInitialStorrage() {
		return initialStorrage;
	}
}
